#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<iostream>
using namespace std;

int s[10]={1,1,2,2,3,3,3,4,4,4};

int len=10;

long cc=0;

bool cmp(int a,int b)
{
	if (a<b)
		return true;
	return false;
}
void perm()
{
	int i,j,k,t;
	int tmp;
	//puts(s);
	//cout<<s<<endl;
	while (1) {
		int i=-1;
		for (j=len-2;j>=0;j--) {
			if (s[j]<s[j+1]) {
				i=j;
				break;
			}
		}
		if (i==-1) break;
		for (j=len-1;j>=i+1;j--) {
			if (s[j]<=s[i]) continue;
			else {
				t=j;
				tmp=s[j];
				break;
			}
		}
		s[t]=s[i];
		s[i]=tmp;
		int k=len-1-i;
		for (j=1;j<=k/2;j++) {
			t=s[i+j];
			s[i+j]=s[len-j];
			s[len-j]=t;
		}
		//puts(s);
		//for(int a=0;a<10;a++){
		//	cout<<s[a];
		//}
		cout<<endl;
		cc++;
	}
}
int main()
{
	perm();
	//int T;
	//scanf("%d",&T);
	//getchar();
	//while (T--) {
		//gets(s);
		//len=strlen(s);
		//sort(s,s+len,cmp);
		//perm();
	//}
	cout<<"OK\ncc="<<cc<<endl;
}
